package ru.ya.kolemik.servcmd.servs;

import java.io.IOException;
import java.util.Calendar;
import java.util.Formatter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import ru.ya.kolemik.servcmd.AbstractServ;
import ru.ya.kolemik.servcmd.View;

/**
 * Just an example of custom Serv
 * @author mixa
 *
 */
public class DateTime extends AbstractServ {
    
    public String doServe(HttpServletRequest request,
            HttpServletResponse response, String command)
            throws ServletException, IOException {
        Formatter fmt = new Formatter();
        Calendar cal = Calendar.getInstance();
        
        fmt.format("%1$td-%1$tm-%1$tY %1$tH:%1$tM:%1$tS", cal);
        String date = fmt.toString();
        request.setAttribute("dateTime", date);
        
        log.debug("Current date and time = " + date);
        
        return null;
    }
    
    @View
    public void view(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        request.getRequestDispatcher("/JSP/dateTime.jsp").include(request,
                response);
    }
}
